package com.chess.chessplay.config;

public class test {

    public static void main(String[] args) {
        String[][] a = {{"1","3"}, {"2","4"}};
        String s = convertToString(a,2,2);
        String[][] b = convertToArray(s, 2, 2);
        a = x(b);
        for(int i = 0; i < a.length; i++){
            for(int j = 0; j < a[i].length; j++){
                System.out.println(a[i][j]);
            }
        }
    }

    public int getRow(String[][] array) {
        int row = 0;
        if (array != null) {
            row = array.length; // 行
        }
        return row;
    }

    public int getCol(String[][] array) {
        int col = 0;
        if (array != null) {
            col = array[0].length; // 列
        }
        return col;
    }

    public static String convertToString(String[][] array, int row, int col) {
        String str = "";
        String tempStr = null;
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                tempStr = array[i][j];
                str = str + tempStr + ",";
            }
        }
        return str;
    }

    public static String[][]	convertToArray(String str, int row, int col){
        String[][]	arrayConvert = new String[row][col];
        int count = 0;
        String[] strArray = str.split(",");
        for(int i = 0 ; i < row ; i ++){
            for(int j = 0 ; j < col ; j ++){
                arrayConvert[i][j] = strArray[count];
                ++ count ;
            }
        }
        return arrayConvert;
    }

    public static String[][] x(String[][] m){
        String[][] l = new String[2][2];

        for(int i = 0; i < m.length; i++){

            for(int j = 0; j < m[i].length; j++){
                l[j][i] = m[i][j];
            }
        }
        return l;
    }
}
